//使用方式说明，import {drawText} from '../utils/index';

/***  this.ctx.fillStyle = '#1b282c';
      this.ctx.font = '30px Arial';
      this.ctx.fillText('你的分数', resultSprite.x + 100, resultSprite.y + 190);
      this.ctx.fillText('分', (750-resultSprite.x) - 120, resultSprite.y + 190);
      this.ctx.save();
      this.ctx.font = '24px Arial';
      drawText(remarks[this.score], resultSprite.x + 100, resultSprite.y + 240,resultSprite.width-200 ,this.ctx, ratio);
**/

export const drawText = function(t, x, y, w, context, scale = 1) {
  var chr = t.split("");
  var temp = "";
  var row = [];

  context.fillStyle = "#ffffff";
  context.font = `${16 * scale}px Arial`;
  context.textBaseline = "middle";

  for (var a = 0; a < chr.length; a++) {
    if (context.measureText(temp).width < w) {
    } else {
      row.push(temp);
      temp = "";
    }
    temp += chr[a];
  }
  row.push(temp);
  for (var b = 0; b < row.length; b++) {
    context.fillText(row[b], x, y + (b + 1) * 20 * scale);
  }
};

export const drawChineseText = function(t, x, y, color, font, context) {
  context.fillText(t, x, y);
  context.fillStyle = color;
  context.font = font;
};
